<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>mixin混合模式</title>
</head>
<body>
    <script>
        let Tool = {
            max(key){
                return this.data.sort((a,b) => b[key] - a[key])[0];
            }
        };

        let Arr = {
            count(key){
                return this.data.reduce((t,i) => t += i[key],0);
            }
        };
        class Lesson{
            constructor(lessons){
                this.lessons = lessons;
            }

            get data(){
                return this.lessons;
            }
        }

        // mixin混合模式
        Object.assign(Lesson.prototype,Tool,Arr);

        let lessons = [
            {"name":"javascript","price":199,"click":89},
            {"name":"mySql","price":299,"click":139},
            {"name":"php","price":199,"click":89}
        ];

        let less = new Lesson(lessons);
        console.log(less.max("click"));
        console.log(less.count("click"));
    </script>
</body>
</html>